unit uEtiquetaNovaQtde;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, JvExMask, JvToolEdit, JvBaseEdits, Buttons,
  FMTBcd, DB, SqlExpr, DBTables;

type
  TfEtiqNovaQtde = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    edQtdeTotal: TJvCalcEdit;
    edEmb: TJvCalcEdit;
    edEtiq: TJvCalcEdit;
    Label3: TLabel;
    btnSair: TBitBtn;
    btnNova: TBitBtn;
    spEtiqNovaQtd: TSQLStoredProc;
    procedure edEmbExit(Sender: TObject);
    procedure edQtdeTotalExit(Sender: TObject);
    procedure btnNovaClick(Sender: TObject);
    procedure btnSairClick(Sender: TObject);
  private
    { Private declarations }
  public
    etiqueta: String;
    sucesso: String;
    { Public declarations }
  end;

var
  fEtiqNovaQtde: TfEtiqNovaQtde;

implementation

uses udm;

{$R *.dfm}

procedure TfEtiqNovaQtde.edEmbExit(Sender: TObject);
begin
  edEtiq.Value := edQtdeTotal.Value/edEmb.Value;
end;

procedure TfEtiqNovaQtde.edQtdeTotalExit(Sender: TObject);
begin
  if (edEmb.Value > 0) then
    edEtiq.Value := edQtdeTotal.Value/edEmb.Value;
end;

procedure TfEtiqNovaQtde.btnNovaClick(Sender: TObject);
var Save_Cursor:TCursor;
  total, emb: Integer;
begin
  sucesso := 'NAO';
  Save_Cursor := Screen.Cursor;
  try
    Screen.Cursor := crHourGlass;
    try
      total := StrToInt(edQtdeTotal.Text);
      emb   := StrToInt(edEmb.Text);
      dm.spEtiq_NQTDE.ParamByName('OLDETIQ').AsString := etiqueta;
      dm.spEtiq_NQTDE.ParamByName('USUARIO').AsString := dm.user;
      dm.spEtiq_NQTDE.ParamByName('QTDTOT').AsString  := edQtdeTotal.Text;
      dm.spEtiq_NQTDE.ParamByName('QTDEMB').AsString  := edEmb.Text;
      dm.spEtiq_NQTDE.ExecProc;
      sucesso := 'SIM';
      MessageDlg('Novas etiquetas geradas com sucesso.', mtWarning, [mbOK],0);
    except
      sucesso := 'NAO';
      MessageDlg('Erro para gerar nova Etiqueta.',
        mtError, [mbOk],0);
      Screen.Cursor := Save_Cursor;
      exit;
    end;
  finally
    Screen.Cursor := Save_Cursor;
  end;
end;

procedure TfEtiqNovaQtde.btnSairClick(Sender: TObject);
begin
  Close;
end;

end.
